/**
 * 版本更新
 */
/**
 * @description 检测版本更新
 * @param allowIgnore 是否允许忽略
 * @returns
 */
import axios from 'axios'
export async function checkUpdate(allowIgnore: boolean) {
  //动态获取线上的资源地址，其实就是vite.config.ts的base的值
  try {
    const version = await axios
      .get('/version.json?s=' + Math.random())
      .then((res) => res.data.version)
    const intVersion = parseInt(version)
    let cacheVersion = localStorage.getItem('Int_version')
    if (!cacheVersion) {
      cacheVersion = intVersion
      localStorage.setItem('Int_version', intVersion)
    }
    if (parseInt(cacheVersion) < intVersion) {
      ElMessageBox.confirm('是否刷新页面重新加载最新版?', '检测到新版本', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        showClose: false,
        closeOnClickModal: false
      }).then(() => {
        localStorage.setItem('Int_version', intVersion)
        window.location.reload()
      })
    }
    // 检测前端资源是否有更新
  } catch (e) {
    return Promise.reject(e)
  }
}
